using System;
using NUnit.Framework;
using System.IO;

namespace ProgrammingLanguageNr1
{
	[TestFixture()]
	public class SymbolTableBuilder_TEST
	{
		static ErrorHandler s_errorHandler = new ErrorHandler();
		
		[Test()]
		public void DefineVariableFromCode ()
		{
			Tokenizer t = new Tokenizer(File.OpenText("code11.txt"), s_errorHandler);
			Parser p = new Parser(t.getTokens(), s_errorHandler);
			p.process();
			
			SymbolTableBuilder symbolTableBuilder = new SymbolTableBuilder(p.getAST(), s_errorHandler);
			symbolTableBuilder.process();
			GlobalScope globalScope = symbolTableBuilder.getGlobalScope();
			
			Assert.IsNotNull(globalScope.resolve("x"));
		}
		
		[Test()]
		public void DefineFunction ()
		{
			Tokenizer t = new Tokenizer(File.OpenText("code12.txt"), s_errorHandler);
			Parser p = new Parser(t.getTokens(), s_errorHandler);
			p.process();
			
			SymbolTableBuilder symbolTableBuilder = new SymbolTableBuilder(p.getAST(), s_errorHandler);
			symbolTableBuilder.process();
			GlobalScope globalScope = symbolTableBuilder.getGlobalScope();
			
			Assert.IsNotNull(globalScope.resolve("foo"));
		}
		
		[Test()]
		public void DeclareAndReferenceFunctionsAndVariables ()
		{
			Tokenizer t = new Tokenizer(File.OpenText("code13.txt"), s_errorHandler);
			Parser p = new Parser(t.getTokens(), s_errorHandler);
			p.process();
			
			SymbolTableBuilder symbolTableBuilder = new SymbolTableBuilder(p.getAST(), s_errorHandler);
			symbolTableBuilder.process();
		}
		
		[Test()]
		public void DeclareVariableInSubscopes ()
		{
			Tokenizer t = new Tokenizer(File.OpenText("code16.txt"), s_errorHandler);
			Parser p = new Parser(t.getTokens(), s_errorHandler);
			p.process();
			
			SymbolTableBuilder symbolTableBuilder = new SymbolTableBuilder(p.getAST(), s_errorHandler);
			symbolTableBuilder.process();
		}
	}
}

